﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Data;
using QLPM.DTO;


namespace QLPM.DAO
{
    public class LoaiBenhDAO
    {
        DataProvider provider;

        public LoaiBenhDAO()
        {
            provider = new DataProvider();    
        }

        public List<LoaiBenh> DanhSachLoaiBenh()
        {
            String sql = "select * from LOAIBENH";
            provider = new DataProvider("LOAIBENH",sql);
            DataTable dt = provider;
            List<LoaiBenh> ds = new List<LoaiBenh>();

            for (int i = 0; i < dt.Rows.Count; i++)
            {
                LoaiBenh lb = new LoaiBenh();
                lb.MaLoaiBenh = Convert.ToInt32(dt.Rows[i]["MaLoaiBenh"].ToString());
                lb.TenLoaiBenh = dt.Rows[i]["TenLoaiBenh"].ToString();
                ds.Add(lb);
            }
            return ds;
        }

        public int ThemLoaiBenh(LoaiBenh lb)
        {
            String sql = String.Format("insert into LOAIBENH(TenLoaiBenh) values('{0}')", lb.TenLoaiBenh);
            return provider.Excute_Non_Query(sql);
        }

        public int XoaLoaiBenh(LoaiBenh lb)
        {
            String sql = String.Format("delete from LOAIBENH where MaLoaiBenh={0}", lb.MaLoaiBenh);
            return provider.Excute_Non_Query(sql);
        }

        public int SuaLoaiBenh(LoaiBenh lb)
        {
            String sql = String.Format("update LOAIBENH set TenLoaiBenh='{1}' where MaLoaiBenh={0} ", lb.MaLoaiBenh, lb.TenLoaiBenh);
            return provider.Excute_Non_Query(sql);
        }
    }
}
